//
//  AppDelegate.m
//  01UI
//
//  Created by dllo on 16/7/14.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "AppDelegate.h"
#import "UIView+Frame.h"
@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
    
    
//    程序的组成结构
//    1.main.m 主要实现了程序的正常运行
//    2.Appdelegate程序的执行者，签订了UIApplicationDelegate(协议方法可选)
//    注意：AppDelegate就是一个普通的类，只不过签订了协议，才有了这么多方法
    
//    3.viewController视图控制器，主要负责试图管理 看得见摸得到的
//    4.main.sb（试图管理） LaunchScreen.sb（负责启动页） 可视化管理 （xcode7以前LanunchScreen.xib）
//    5.Assets.xcassets 主要用来管理图片素材 （xcode7以前叫Images。xcassets）
//    6.Info.plist (工程配置文件)
    
    
//    模拟器
//    command + 1~5 改变模拟器大小
//    command + ←/→ 横竖屏切换
    
    
//    ios概述
//    ios 正确的写法 iOS
    
    
    
//    1.UIWindow (程序中，只有一个主window)
//    1.取消程序的可视化入口，Main.sb
//    2.创建主window对象
//UIScreen系统屏幕类
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];//创建主window，使其大小与主屏幕一样
    _window.backgroundColor = [UIColor whiteColor];//2给你创建的窗口填颜色 UIColor系统颜色
//   3 让window显示，并成为主窗口
//    
    [_window makeKeyAndVisible];//成为主窗口并显示
////    4.设置window的主窗口
////    xcode7以后，必须设置rootController，否则，在该方法结束时，会崩溃
    _window.rootViewController = [[UIViewController alloc] init];
    
    
    
    
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
    view.backgroundColor = [UIColor redColor];
//    [_window addSubview:view];
    
    UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(80, 80, 100, 100)];
    view1.backgroundColor = [UIColor blueColor];
//    [_window addSubview:view1];
//    [view addSubview:view1];
    
    view1.tag = 1000;
    UIView *view3 = [_window viewWithTag:1000];
//    [_window addSubview:view3];
    UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(50, 50, 120, 120)];
    view2.backgroundColor = [UIColor blackColor];
//    [_window addSubview:view2];
    NSLog(@"%@",_window.subviews);
//    [view1 addSubview:view2];
    
//    [view2 addSubview:view1];
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(40, 40, 200, 200)];
    label.backgroundColor = [UIColor greenColor];
//    [_window addSubview:label];
//
    label.text = @"放假了gfgfgfgfgfg";
    label.textColor = [UIColor blueColor];
    label.textAlignment = NSTextAlignmentCenter;
    label.font = [UIFont systemFontOfSize:30];
//    label.numberOfLines = 6;
    
    UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(150, 150, 200, 40)];
    textField.backgroundColor = [UIColor redColor];
//    [_window addSubview:textField];
    textField.alpha = 0.5;
//    textField.text = @"注册";
    textField.textAlignment = NSTextAlignmentLeft;
    textField.borderStyle = UITextBorderStyleLine;
    
    textField.placeholder = @"请输入爱好";
    textField.clearsOnBeginEditing = YES;
    
   
    UIButton *button1 = [[UIButton alloc] initWithFrame:CGRectMake(50, 50, 100, 40)];
    button1.backgroundColor = [UIColor redColor];
//    [_window addSubview:button1];
    [button1 addTarget:self action:@selector(buttonClicked) forControlEvents:UIControlEventTouchUpInside];
    [button1 setTitle:@"奥运" forState:UIControlStateNormal];
    [button1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    
    
        
    
    
    
//    [_window insertSubview:view1 atIndex:1];
    
//    3uiwindow 继承与uiview
    
//    2.uiview（与NSObject相似，是ui阶段的根类，大部分ui控件继承与uiview）
    
//    学习新类
//    1.需要包含那些初始化方法
//    2.包含哪些方法和属性
//    创建UIView
//    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(100, 42, 200, 300)];
//    
//    view.backgroundColor = [UIColor greenColor];
//    
//    [_window addSubview:view];
////    遇到uiview的子类，都可以用以上方式创建和显示
//    UIView在屏幕显示为矩形
    
    
//    iOS系统坐标系
//    1.与数学中的坐标系不同y的正方向是向下的
//    原点是屏幕的左上角
    
//    frame bounds center(uiview的属性)
//    1.frame (x,y,width,height)视图在其父视图上的位置
//    2.bounds (x,y,width,height)自己试图本身的坐标系
//    3.center 中心点(影响试图的位置)
    
//    view.frame = CGRectMake(10, 10, 80, 80);
    
//    bounds x,y修改的本身的坐标系，影响它的子视图
//    bounds width height修改的是本身的大小，，会以中心点收缩扩张
    
//    bounds的改变，不会改变该视图的位置
    
//    view.bounds = CGRectMake(-10, -10, 80, 80);//bounds影响子视图的frame,改变坐标系
    
//    CGRect 和 cgpoint
    
//    bounds 对视图的影响测试
    
    
//    UIView *subView = [[UIView alloc] initWithFrame:CGRectMake(-20, -20, 40, 40)];
//    subView.backgroundColor = [UIColor yellowColor];
//    [view addSubview:subView];
//    
//    NSLog(@"%@",NSStringFromCGRect(view.frame));
////    NSLog(@"%@",NSStringFromCGRect(view.center));
//    view.bounds = CGRectMake(0,0 ,100 ,100 );
//    NSLog(@"%@",NSStringFromCGRect(view.frame));
    
    
    
//    改变绿色view的大小，width变成 100
//    方法1
//    view.frame = CGRectMake(view.frame.origin.x, view.frame.origin.y, 100, view.frame.size.height);
////    方法2
//    CGRect rect = view.frame;
//    rect.size.width = 100;
//    view.frame = rect;
    
    
//    view.frame.size.width = 100;错误
//    NSLog(@"%@");
    
//    view.frame是get方法
//    frame.size 结构体
//    oc和c的内容结合，是一个常量
    
    
    
//    view.sy_width = 23;
    
    
//    UIView *testView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
//    
//    testView.backgroundColor = [UIColor cyanColor];
//    [_window addSubview:testView];
//    [testView removeFromSuperview];
//    testView.backgroundColor = [UIColor blueColor];
    
//    alpha 透明度 0~1 默认值1.0
    
//    testView.alpha = 0.5;
//   tag 标记（编号）默认为0
//    testView.tag = 1000;
//    根据对应的tag获取到view __kindof
//    UIView *view1 = [_window viewWithTag:1000];
//    subViews子试图们
//    UIView *arrayView = [_window.subviews objectAtIndex:0];
//    NSLog(@"%@",arrayView);
//    superView父视图
//    testView.subviews
    
//    hidden隐藏（yes）和显示（no）默认值是no
//    testView.hidden = YES;
    
//    视图层级
//    [testView insertSubview:<#(nonnull UIView *)#> atIndex:<#(NSInteger)#>];
//testView insertSubview:<#(nonnull UIView *)#> aboveSubview:<#(nonnull UIView *)#>
//testView insertSubview:<#(nonnull UIView *)#> belowSubview:<#(nonnull UIView *)#>

    
//    UIView *firstView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 80, 80)];
//    firstView.backgroundColor = [UIColor greenColor];
//    UIView *secondView = [[UIView alloc] initWithFrame:CGRectMake(10, 10, 80, 80)];
//    secondView.backgroundColor = [UIColor orangeColor];
//    UIView *lastView = [[UIView alloc]initWithFrame:CGRectMake(20, 20, 80, 80)];
//    lastView.backgroundColor = [UIColor blackColor];
//    [_window addSubview:firstView];
//    [_window addSubview:secondView];
//    NSLog(@"%@",_window.subviews);
//    [_window insertSubview:secondView atIndex:2];
//    
//    UILabel用来显示文本
//    如果类没有自己的初始化方法，则使用父类的
//    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20, 100, 300, 100)];
//    label.backgroundColor = [UIColor yellowColor];
//    [_window addSubview:label];
//////    label的属性
//    label.text = @"hdfhdferyutuerughuygfffffffuyrgytrtrtrt";
////    textcolor 文本颜色
//    label.textColor = [UIColor blackColor];
////    font 默认值17
//    label.font = [UIFont systemFontOfSize:10];
//    label.font = [UIFont boldSystemFontOfSize:20];
////    textAlignment 对齐方式(默认是左)
////    label.textAlignment = NSTextAlignmentCenter;
////    numberOfLines(默认为1行)
//    label.numberOfLines = 3;
//    
//    
////    UIButton (用来点的)
//    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
//    button.sy_x = 0;
//    button.sy_y = 0;
//    button.sy_width = 100;
//    button.sy_height = 100;
//    button.backgroundColor = [UIColor blueColor];
//    
//    [_window addSubview:button];
////    给button添加事件
//    [button addTarget:self action:@selector(buttonClicked) forControlEvents:UIControlEventTouchUpInside];
//    
////    给button添加文字
//    [button setTitle:@"dianwo" forState:UIControlStateNormal];
//    
//    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
//    
////    UITextField
//    UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(100, 400, 200, 300)];
//    textField.backgroundColor = [UIColor redColor];
//    [_window addSubview:textField];
////    给输入框赋了初值
//    textField.text = @"文字";
//    textField.textColor = [UIColor blueColor];
////    borderStyleNone
////    borderStyle
////    UITextBorderStyleLine有边缘线
//    textField.borderStyle = UITextBorderStyleLine;
//    
//    textField.placeholder = @"请输入您的爱好"; //占位符
//    textField.clearsOnBeginEditing = YES;
//    
    
    
    
    
    
//    command + k收起显示键盘
    
    
    return YES;
}
//- (void)buttonClicked
//{
//    [_window endEditing:YES];
//    NSLog(@"我被点了");
//}

- (void)buttonClicked
{
    NSLog(@"奥运会");
}


- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
